export PKG_CONFIG_PATH := $(PKG_CONFIG_PATH):/usr/local/lib/pkgconfig

TARGET=quarantine-helper
all: $(TARGET)

REVISION := $(shell git describe --tags --match 'v*' --always --dirty 2>/dev/null)
REVISIONDATE := $(shell git log -1 --pretty=format:'%ad' --date short 2>/dev/null)
PKG := code.alibaba-inc.com/agit/quarantine-helper/version
LDFLAGS = -s -w
ifneq ($(strip $(REVISION)),) # Use git clone
	LDFLAGS += -X $(PKG).revision=$(REVISION) \
		   -X $(PKG).revisionDate=$(REVISIONDATE)
endif

quarantine-helper: $(shell find . -name '*.go')
#	GOOS=linux GOARCH=amd64 go build -ldflags="$(LDFLAGS)" -o $(TARGET)
	go build -ldflags="$(LDFLAGS)" -o $(TARGET) -mod=vendor

test: quarantine-helper lint
	go test ./...
	make -C test

lint:
	@echo "==========   golint start  =========="
	@golint ./... 
	@echo "========== golint finished =========="

clean:
	rm -f "$(TARGET)"

install:
	cp quarantine-helper /usr/local/bin

uninstall:
	rm /usr/local/bin/quarantine-helper

.PHONY: all clean test
